#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import configparser
from django.conf import settings

def check_url(url):
    try:
        r = requests.get(url, timeout=10)
        return r.status_code
    except Exception as e:
        return e

def main():
    urls_state = []
    cfg = configparser.ConfigParser()
    cfg.read(settings.CONFIG_PATH,encoding='utf-8')
    # print('网页访问:')
    urls = cfg.items('url')
    tasks = []
    for url in urls:
        status_code = check_url(url[1])
        if status_code == 200:
            urls_state.append([0,1])
            print('%s  %s ok' % (url[0],url[1]))
        else:
            urls_state.append([1, 1,url[0]+' ConnectTimeout'])
            print('%s  %s %s fail' % (url[0], url[1],status_code))
    print('-->urls_state',urls_state)
    return urls_state

def main():
    urls_state = []
    cfg = configparser.ConfigParser()
    cfg.read(settings.CONFIG_PATH,encoding='utf-8')
    # print('网页访问:')
    urls = cfg.items('url')
    for url in urls:
        status_code = check_url(url[1])
        if status_code == 200:
            urls_state.append([0,1])
            print('%s  %s ok' % (url[0],url[1]))
        else:
            urls_state.append([1, 1,url[0]+' ConnectTimeout'])
            print('%s  %s %s fail' % (url[0], url[1],status_code))
    return urls_state

